<!DOCTYPE html>
<html>

<head>
  <title>Continuum</title>
  <script id="adobe_dtm" src="https://www.redhat.com/dtm.js" type="text/javascript"></script>
  <script src="/assets/javascript/highlight.pack.js" type="text/javascript"></script>
  <META HTTP-EQUIV='Content-Security-Policy' CONTENT="default-src 'none'; script-src 'self' 'unsafe-eval' 'sha256-ANpuoVzuSex6VhqpYgsG25OHWVA1I+F6aGU04LoI+5s=' 'sha256-ipy9P/3rZZW06mTLAR0EnXvxSNcnfSDPLDuh3kzbB1w=' js.bizographics.com https://www.redhat.com assets.adobedtm.com jsonip.com https://ajax.googleapis.com https://www.googletagmanager.com https://www.google-analytics.com https://use.fontawesome.com; style-src 'self' https://fonts.googleapis.com https://use.fontawesome.com; img-src 'self' *; media-src 'self' ; frame-src https://www.googletagmanager.com https://www.youtube.com; frame-ancestors 'none'; base-uri 'none'; object-src 'none'; form-action 'none'; font-src 'self' https://use.fontawesome.com https://fonts.gstatic.com;">
  <META HTTP-EQUIV='X-Frame-Options' CONTENT="DENY">
  <META HTTP-EQUIV='X-XSS-Protection' CONTENT="1; mode=block">
  <META HTTP-EQUIV='X-Content-Type-Options' CONTENT="nosniff">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="Quarkus: Supersonic Subatomic Java">
  <meta name="twitter:card" content="summary_large_image">
  <meta name="twitter:site" content="@QuarkusIO"> 
  <meta name="twitter:creator" content="@QuarkusIO">
  <meta property="og:url" content="https://quarkus.io/vision/continuum" />
  <meta property="og:title" content="Continuum" />
  <meta property="og:description" content="Quarkus: Supersonic Subatomic Java" />
  <meta property="og:image" content="/assets/images/quarkus_card.png" />
  <link rel="canonical" href="https://quarkus.io/vision/continuum">
  <link rel="shortcut icon" type="image/png" href="/favicon.ico" >
  <link rel="stylesheet" href="https://quarkus.io/guides/stylesheet/config.css" />
  <link rel="stylesheet" href="/assets/css/main.css" />
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous">
  <link rel="alternate" type="application/rss+xml"  href="https://quarkus.io/feed.xml" title="Quarkus">
  <script src="https://quarkus.io/assets/javascript/goan.js" type="text/javascript"></script>
  <script src="https://quarkus.io/assets/javascript/hl.js" type="text/javascript"></script>
</head>

<body class="vision">
  <!-- Google Tag Manager (noscript) -->
  <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-NJWS5L"
  height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
  <!-- End Google Tag Manager (noscript) -->

  <div class="nav-wrapper">
  <div class="grid-wrapper">
    <div class="width-12-12">
      <input type="checkbox" id="checkbox" />
      <nav id="main-nav" class="main-nav">
  <div class="container">
    <div class="logo-wrapper">
      
        <a href="/"><img src="/assets/images/quarkus_logo_horizontal_rgb_600px_reverse.png" class="project-logo" title="Quarkus"></a>
      
    </div>
    <label class="nav-toggle" for="checkbox">
      <i class="fa fa-bars"></i>
    </label>
    <div id="menu" class="menu">
      <span>
        <a href="/get-started/" class="">Get Started</a>
      </span>
      <span>
        <a href="/guides/" class="">Guides</a>
      </span>
      <span>
        <a href="/community/" class="">Community</a>
      </span>
      <span>
        <a href="/support/" class="">Support</a>
      </span>
      <span>
        <a href="/blog/" class="">Blog</a>
      </span>
      <span>
        <a href="https://code.quarkus.io" class="button-cta secondary white">Start Coding</a>
      </span>
    </div>
  </div>
      </nav>
    </div>
  </div>
</div>

  <div class="content">
    <div class="grid-wrapper gs-header">
  <div class="grid__item width-12-12">
    <h1 class="text-caps">Continuum</h1>
  </div>
</div>
<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>For years, the client-server architecture has been the de-facto standard to build applications.
But a major shift happened.
The <em>one model rules them all</em> age is over.
A new range of applications and architecture styles has emerged and impacts how code is written and how applications are deployed and executed.
HTTP microservices, reactive applications, message-driven microservices and serverless are now central players in modern systems.</p>
</div>
<div class="paragraph">
<p>Quarkus has been designed with this new world in mind, and provides first-class support for these different paradigms.
Quarkus development model morphs to adapt itself to the type of application you are developing.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="http-microservices"><a class="anchor" href="#http-microservices"></a>HTTP microservices</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Let’s start with the basic: HTTP microservices.
In this context, you need to develop an HTTP endpoint, often called REST or CRUD.
You process incoming HTTP requests, and to do so you often need to rely on others services, such as databases, or another HTTP service.</p>
</div>
<div class="paragraph">
<p>For this type of application, Quarkus relies on well-known standards such as JAX-RS, JPA and MicroProfile Rest Client.
Let&#8217;s take a very simple application handling <em>fruits</em>. The code would be something like:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@Path("fruits")
@Produces("application/json")
@Consumes("application/json")
public class FruitResource {

    @Inject
    EntityManager entityManager;

    @GET
    public List&lt;Fruit&gt; get() {
        return entityManager.createNamedQuery("Fruits.findAll", Fruit.class)
              .getResultList();
    }

    @GET
    @Path("{id}")
    public Fruit getSingle(@PathParam Integer id) {
        Fruit entity = entityManager.find(Fruit.class, id);
        if (entity == null) {
            throw new WebApplicationException("Fruit with id of " + id + " does not exist.", 404);
        }
        return entity;
    }

    @POST
    @Transactional
    public Response create(Fruit fruit) {
        if (fruit.getId() != null) {
            throw new WebApplicationException("Id was invalidly set on request.", 422);
        }

        entityManager.persist(fruit);
        return Response.ok(fruit).status(201).build();
    }

    // ...
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>If you are a Java EE or Spring user, this development model should look familiar.
You expose a <em>resource</em> containing methods annotated with <code>@GET</code>, <code>@POST</code>&#8230;&#8203; to handle the different requests.
The <em>path</em> is specified using the <code>@Path</code> annotation.</p>
</div>
<div class="paragraph">
<p>JPA users will recognize the <code>EntityManager</code> used to access the database.
Finally, methods requiring a transaction are simply annotated with <code>@Transactional</code>.</p>
</div>
<div class="paragraph">
<p>Let&#8217;s now imagine you need to access another HTTP endpoint.
You can use a HTTP client directly, this is nothing more than repeating boilerplate code.
Quarkus provides a way to call HTTP endpoint easily using the MicroProfile Rest Client API.</p>
</div>
<div class="paragraph">
<p>First declare your service as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@Path("/v2")
@RegisterRestClient
public interface CountriesService {

    @GET
    @Path("/name/{name}")
    @Produces("application/json")
    Set&lt;Country&gt; getByName(@PathParam("name") String name);
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>For each call you are intending to do, add a method and use annotations to describe the behavior.</p>
</div>
<div class="paragraph">
<p>Then, in your resource, just use the <code>CountriesService</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@Path("/country")
public class CountriesResource {

    @Inject
    @RestClient
    CountriesService countriesService;

    @GET
    @Path("/name/{name}")
    @Produces(MediaType.APPLICATION_JSON)
    public Set&lt;Country&gt; name(@PathParam("name") String name) {
        return countriesService.getByName(name);
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>But you may be wondering where the URL is configured as it&#8217;s not in the code.
Remember, it must not be hard-coded because the url likely depends on the environment.
The URL is configured in the application configuration:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="text" class="language-text hljs"># the format is interface-name/mp-rest/url=the-service-url
org.acme.restclient.CountriesService/mp-rest/url=https://restcountries.eu/rest</code></pre>
</div>
</div>
<div class="paragraph">
<p>The url can now be updated during the deployment or at launch time using system properties or environment variables.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="being-reactive"><a class="anchor" href="#being-reactive"></a>Being reactive</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Application requirements have changed drastically over the last few years.
For any application to succeed in the era of cloud computing, big data or IoT, going reactive is increasingly becoming the architecture style to follow.</p>
</div>
<div class="paragraph">
<p>Today’s users embrace applications that have milliseconds of response time, 100% uptime, lower latency, push data instead of pull, higher throughput and elasticity.
However, these features are nearly impossible to achieve by using <em>yesterday’s software architecture</em> without a huge investment in resources, infrastructure and tooling.
The world changed and having dozen of servers, long response time (&gt; 500 ms), downtime due to maintenance or waterfalls of failures does not meet the expected user experience.</p>
</div>
<div class="paragraph">
<p>Quarkus stands with you on your path to reactive.
First, you can implement asynchronous HTTP endpoint as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@GET
@Path("/greeting/{name}")
public CompletionStage&lt;String&gt; greetings(@PathParam("name") String name) {
    return reactiveService.getAsyncGreetings(name);
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Method actions can compose asynchronous operations and complete the result when everything is done without blocking threads.
This greatly improves resource consumption and elasticity.</p>
</div>
<div class="paragraph">
<p>But, what about streams?
Generating a <em>server-sent event</em> response with Quarkus is just as simple:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@Produces(MediaType.SERVER_SENT_EVENTS)
@GET
@Path("/neo")
public Publisher&lt;String&gt; stream() {
    return service.getStream();
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>This method returns a Reactive Streams <code>Publisher</code>.
To provide this stream, you can either use <a href="https://github.com/ReactiveX/RxJava">Rx Java 2</a> or <a href="https://www.smallrye.io/smallrye-reactive-streams-operators/">MicroProfile Reactive Streams Operators</a>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@Produces(MediaType.SERVER_SENT_EVENTS)
@GET
@Path("/neo")
public Publisher&lt;String&gt; stream() {
    return ReactiveStreams.of("a", "b", "c")
           .map(String::toUpperCase)
           .buildRs();
}</code></pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="message-driven-microservices"><a class="anchor" href="#message-driven-microservices"></a>Message-driven microservices</h2>
<div class="sectionbody">
<div class="paragraph">
<p>However, HTTP characteristics prohibit implementing <a href="https://www.reactivemanifesto.org/">reactive systems</a>, where all the components interact using asynchronous messages passing.
But no worries, Quarkus is perfectly suited to implement message-driven microservices and reactive systems.</p>
</div>
<div class="paragraph">
<p>First, you can consume messages from various brokers such as AMQP or Kafka, and process these messages smoothly:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@ApplicationScoped
public class HealthDataProcessor {

  @Incoming("health")
  @Outgoing("heartbeat")
  public double filtered(Health health) {
    return health.getHeartbeat();
  }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>@Incoming</code> and <code>@Outgoing</code> annotations are part of <a href="https://www.smallrye.io/smallrye-reactive-messaging">Reactive Messaging</a>.
They are used to express from which <em>stream</em> you are consuming and to which stream you are sending.
Thanks to Reactive Messaging you can consume and send messages from and to different brokers and transports such as HTTP, Kafka, or <a href="http://camel.apache.org">Apache Camel</a>.</p>
</div>
<div class="paragraph">
<p>Sometimes you need more than just handling messages one by one.
You can also express your message processing logic using reactive programming as illustrated in the following snippet:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@Incoming("health")
@Outgoing("output")
public Publisher&lt;KafkaMessage&lt;String, JsonObject&gt;&gt; filterState(Flowable&lt;MqttMessage&gt; input) {
    return input
      .map(message -&gt; Buffer.buffer(message.getPayload()).toJsonObject())
      .map(json -&gt; json.getJsonObject("state"))
      .distinctUntilChanged(json -&gt; json.getString("state")) // Filter on the "State" key of the json object.
      .doOnNext(json -&gt; LOGGER.info("Forwarding new state '{}' to Kafka", json.encode()))
      .map(json -&gt; KafkaMessage.of("state", "neo", json));
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Stream-based manipulation can either use Rx Java 2 (as in the previous snippet) or MicroProfile Reactive Streams Operators.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="functions-as-a-service-and-serverless"><a class="anchor" href="#functions-as-a-service-and-serverless"></a>Functions as a Service and Serverless</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Thanks to their stellar startup time and low memory usage, you can implement functions using Quarkus to be used in serverless environments.
If you are using AWS Lambda, your Quarkus function looks like:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">public class HelloLambda implements RequestHandler&lt;HelloRequest, String&gt; {

    @Inject
    HelloGreeter greeter;

    @Override
    public String handleRequest(HelloRequest request, Context context) {
        return greeter.greet(request.firstName, request.lastName);
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>You can use any of the Quarkus features in your function and benefit from the fast startup and low memory utilization. With Quarkus, you can embrace this new world without having to change your programming language.</p>
</div>
</div>
</div>

  </div>

  <div class="content project-footer">
  <div class="footer-section">
    <div class="logo-wrapper">
      <a href="/"><img src="/assets/images/quarkus_logo_horizontal_rgb_reverse.svg" class="project-logo" title="Quarkus"></a>
    </div>
  </div>
  <div class="grid-wrapper">
    <p class="grid__item width-3-12">Quarkus is open. All dependencies of this project are available under the <a href='https://www.apache.org/licenses/LICENSE-2.0' target='_blank'>Apache Software License 2.0</a> or compatible license.<br /><br />This website was built with <a href='https://jekyllrb.com/' target='_blank'>Jekyll</a>, is hosted on <a href='https://pages.github.com/' target='_blank'>Github Pages</a> and is completely open source. If you want to make it better, <a href='https://github.com/quarkusio/quarkusio.github.io' target='_blank'>fork the website</a> and show us what you’ve got.</p>

    
      <div class="width-1-12 project-links">
        <span>Navigation</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="/">Home</a></li>
          
            <li><a href="/guides">Guides</a></li>
          
            <li><a href="/community/#contributing">Contribute</a></li>
          
            <li><a href="/faq">FAQ</a></li>
          
            <li><a href="/get-started">Get Started</a></li>
          
        </ul>
      </div>
    
      <div class="width-1-12 project-links">
        <span>Contribute</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="https://twitter.com/quarkusio">Follow us</a></li>
          
            <li><a href="https://github.com/quarkusio">GitHub</a></li>
          
            <li><a href="/security">Security&nbsp;policy</a></li>
          
        </ul>
      </div>
    
      <div class="width-1-12 project-links">
        <span>Get Help</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="https://groups.google.com/forum/#!forum/quarkus-dev">Forums</a></li>
          
            <li><a href="https://quarkusio.zulipchat.com">Chatroom</a></li>
          
        </ul>
      </div>
    

    
      <div class="width-3-12 more-links">
        <span>Quarkus is made of community projects</span>
        <ul class="footer-links">
          
            <li><a href="https://vertx.io/" target="_blank">Eclipse Vert.x</a></li>
          
            <li><a href="https://microprofile.io" target="_blank">Eclipse MicroProfile</a></li>
          
            <li><a href="https://hibernate.org" target="_blank">Hibernate</a></li>
          
            <li><a href="https://netty.io" target="_blank">Netty</a></li>
          
            <li><a href="https://resteasy.github.io" target="_blank">RESTEasy</a></li>
          
            <li><a href="https://camel.apache.org" target="_blank">Apache Camel</a></li>
          
            <li><a href="https://code.quarkus.io/" target="_blank">And many more...</a></li>
          
        </ul>
      </div>
    
  </div>
</div>
  <div class="content redhat-footer">
  <div class="grid-wrapper">
    <span class="licence">
      <i class="fab fa-creative-commons"></i><i class="fab fa-creative-commons-by"></i> <a href="https://creativecommons.org/licenses/by/3.0/" target="_blank">CC by 3.0</a> | <a href="https://www.redhat.com/en/about/privacy-policy">Privacy Policy</a>
    </span>
    <span class="redhat">
      Sponsored by
    </span>
    <span class="redhat-logo">
      <a href="https://www.redhat.com/" target="_blank"><img src="/assets/images/redhat_reversed.svg"></a>
    </span>
  </div>
</div>


  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js" integrity="sha384-8gBf6Y4YYq7Jx97PIqmTwLPin4hxIzQw5aDmUg/DDhul9fFpbbLcLh3nTIIDJKhx" crossorigin="anonymous"></script>
  <script type="text/javascript" src="/assets/javascript/mobile-nav.js"></script>
  <script type="text/javascript" src="/assets/javascript/scroll-down.js"></script>
  <script src="/assets/javascript/satellite.js" type="text/javascript"></script>
  <script src="https://quarkus.io/guides/javascript/config.js" type="text/javascript"></script>
  <script src="/assets/javascript/search-filter.js" type="text/javascript"></script>
  <script src="/assets/javascript/back-to-top.js" type="text/javascript"></script>
</body>

</html>
